Our Second R-Markdown

Grupo 8

2021-05-06

First analysis and graphs test from the dataset

Sex Distribution

Code:

pie3D(c(women,men),main = "Sex Distribution", 
      labels = c(paste(women,"%"),paste(men,"%")),
      col = c("turquoise","lightblue"),labelcex = 1, 
      explode = 0.1,start = 3 ,theta = 1.2, mar = c(6,6,6,6))
legend(-0.9,-0.8,c("Women","Men"),fill = c("turquoise","lightblue"))

In this graph we can observe the sex distribution. There is a much higher percentage of men in the dataset.

Diabetic Pacients Distribution

Code:

pie3D(c(diabPerc,notDiabPerc),main = "Diabetics Distribution", 
      labels = c(paste(diabPerc,"%"),paste(notDiabPerc,"%")),
      col = c("red","lightgreen"),labelcex = 1, explode = 0.1,start = 2.9 ,
      theta = 1.1, mar = c(6,6,6,6))
legend(-1.1,1.15,c("Diabetic","Non Diabetic"),fill = c("red","lightgreen"))

Almost one out of three patients is diabetic.

Women older than 50 y/o Density Distribution

Code:

womenMoreThan50 <- dataset[which(dataset$EDAD > 50 & dataset$SEXO == "FEME"), ] 
womenMoreThan50 %>% 
  ggplot(aes(x=EDAD)) + 
  geom_density(fill = "#b19cd9", color = "#e1ecef", alpha = 0.8) + 
  ggtitle("Women older than 50 y/o Density")

In this graph it is possible to visually understand how women are distributed according to their age.

Males and women older than 50 y/o Density Distribution

Code:

ggplot(dataset, aes(x = EDAD, fill = SEXO)) +
  geom_density(alpha = 0.4) +
  theme_ridges() +
  scale_fill_discrete(name = "Gender", labels = c("Female","Male")) +
  theme(legend.position = "top")

In this graph it is possible to visually understand how women and men are distributed according to their age.

Procedure on diabetics patients

Code:

diab <- dataset[which(dataset$DIABETES == "1"),] #agregarle transparencia al color de las areas
diab %>% 
  ggplot(aes(x= EDAD, fill = PROCEDIMIENTO)) +
  geom_density(alpha = 0.8) +
  theme_ridges() +
  scale_fill_discrete(name = "Procedimiento", labels = c("Cirugia","Angioplastia","Endovalvula")) +
  theme(legend.position = "top")

  ggtitle("Densidad de diferentes procedimientos en pacientes diabeticos segun la edad")
## $title
## [1] "Densidad de diferentes procedimientos en pacientes diabeticos segun la edad"
## 
## attr(,"class")
## [1] "labels"

Procedure on diabetic patients

Code:

diabFiltered <- diab[which(diab$TIPO.DE.CIRUGIA != "#N/A"),]
diabFiltered %>% 
  ggplot(aes(x=TIPO.DE.CIRUGIA)) + 
  geom_bar( ) +
  scale_fill_brewer() 

  theme(legend.position="top")
## List of 1
##  $ legend.position: chr "top"
##  - attr(*, "class")= chr [1:2] "theme" "gg"
##  - attr(*, "complete")= logi FALSE
##  - attr(*, "validate")= logi TRUE
  ggtitle("Density of different procedures on diabetic^-1 patients")
## $title
## [1] "Density of different procedures on diabetic^-1 patients"
## 
## attr(,"class")
## [1] "labels"

Procedures on patients with ejection fraction less than 50

Code:

plot_ly(
  y = c(freqCirugiaFEY,freqAngioFEY,freqEndovalvFEY),
  x = xVar,
  name = "PROCEDIMIENTO DE FEY < 50 ",
  type = "bar",
  marker = list(color = c("#83DC4D","#0C9B21","#7BBB84","#9DFBAB"))) %>%
  layout(title = "Procedimientos de pacientes con fraccion de eyeccion menor a 50")

Procedures on patients younger than 50 y/o

Code:

edadMenorA55 <- dataset[which(dataset$EDAD < 55),]
procedimientosAge55 <- factor(edadMenorA55$PROCEDIMIENTO)
freqTable2 <- as.vector(table(procedimientosAge55))
freqAngio55 <- as.numeric(freqTable2[1])
freqCirugia55 <- as.numeric(freqTable2[2])
freqEndovalv55 <- 0

plot_ly(
  y = c(freqCirugia55,freqAngio55,freqEndovalv55),
  x = xVar,
  name = "Procedimientos de pacientes con edad menor a 55",
  type = "bar",
  marker = list(color = c("E9ADF9","F9ADBD","F9ADE3","F9C3AD"))) %>%
  layout(title = "Procedimientos de pacientes con edad menor a 55")

Prodecures on patients older than 70 y/o

Code:

edadMayorA70 <- dataset[which(dataset$EDAD > 70),]
procedimientos <- factor(edadMayorA70$PROCEDIMIENTO)
freqTable3 <- as.vector(table(procedimientos))
freqAngio <- as.numeric(freqTable3[1])
freqCirugia <- as.numeric(freqTable3[2])
freqEndovalv <- as.numeric(freqTable3[4])

plot_ly(
  y = c(freqCirugia,freqAngio,freqEndovalv),
  x = xVar,
  name = "Procedimientos de pacientes con edad mayor a 70",
  type = "bar",
  marker = list(color = c("E9ADF9","F9ADBD","F9ADE3","F9C3AD"))) %>%
  layout(title = "Procedimientos de pacientes con edad mayor a 70") 

Procedures on patients

Code:

datasetFilteredPocedimiento <- dataset[which(dataset$PROCEDIMIENTO != "CIRUGIA, ENDOVALVULA"),]
datasetFilteredPocedimiento %>% 
  ggplot(aes(x= EDAD, fill = PROCEDIMIENTO)) +
  geom_density(alpha = 0.8) +
  theme_ridges() +
  scale_fill_discrete(name = "Procedimiento", labels = c("Cirugia","Angioplastia","Endovalvula")) +
  theme(legend.position = "top")+
  ggtitle("Densidad de diferentes procedimientos segun la edad")

## Graphs {.tabset .tabset-fade .tabset-pills .unnumbered}

<50 y/o

!

>70 y/o

!